package com.andnnl.sync;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.Collectors;

/**
 * Created by chenss on 2020/10/30.
 */
public class SyncTest {
    static Logger logger= LoggerFactory.getLogger(SyncTest.class);
    public static boolean sign = false;
    public static void main(String[] args) {
        Thread Thread01 = new Thread(() -> {
            int i = 0;
            while (!sign) {
                i++;
                add(i);
            }
            logger.info("exit thread 1");
        });
        Thread Thread02 = new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException ignore) {
            }
            sign = true;
            logger.info("vt.sign = true  while (!sign)");
        });
        Thread01.start();
        Thread02.start();
    }

    public static int add2(int i) {
//        System.out.println("s");
        return i + 1;
    }
    public static synchronized int add(int i) {
        return i + 1;
    }

}
